package cn.com.xf.dao.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import cn.com.xf.dao.TbdamagedgoodsDAO;
import cn.com.xf.dao.support.XFSqlMapClientDaoSupport;
import cn.com.xf.domain.Tbdamagedgoods;
import cn.com.xf.domain.Tbdamagedimage;
import cn.com.xf.domain.Tbdamagedunknown;
import net.sf.json.JSONObject;
@Repository
public class TbdamagedgoodsDAOImpl extends XFSqlMapClientDaoSupport implements TbdamagedgoodsDAO {
	public TbdamagedgoodsDAOImpl() {
		super();
	}

	@Override
	public List<Tbdamagedgoods> selectDamaged(int begin, int pageSize, String orderid, String entersite,String entertimeStart,String entertimeEnd) {
		Map<String, Object> map = new HashMap<String, Object>();
		int end = begin + pageSize;
		begin = begin + 1;
		map.put("begin", begin);
		map.put("end", end);
		map.put("orderid", orderid);
		map.put("entersite", entersite);
		map.put("entertimeStart", entertimeStart);
		map.put("entertimeEnd", entertimeEnd);
		return getSqlMapClientTemplate().queryForList("TBDAMAGEDGOODS.selectDamaged", map);
	}

	@Override
	public Integer selectDamagedCount(String orderid, String entersite,String entertimeStart,String entertimeEnd) {
		// TODO Auto-generated method stub
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("orderid", orderid);
		map.put("entersite", entersite);
		map.put("entertimeStart", entertimeStart);
		map.put("entertimeEnd", entertimeEnd);
		return (Integer) getSqlMapClientTemplate().queryForObject("TBDAMAGEDGOODS.selectDamagedCount", map);
	}

	@Override
	public List<Tbdamagedgoods> selectUnknown(int begin, int pageSize, String entersite, 
			String recedateStart,String recedateEnd,String receclass,String memo,
			String goodsid,String applysite) {
		Map<String, Object> map = new HashMap<String, Object>();
		int end = begin + pageSize;
		begin = begin + 1;
		map.put("begin", begin);
		map.put("end", end);
		map.put("entersite", entersite);
		map.put("recedateStart", recedateStart);
		map.put("recedateEnd", recedateEnd);
		map.put("receclass", receclass);
		map.put("memo", memo);
		map.put("goodsid", goodsid);
		map.put("applysite", applysite);
		if(applysite ==null || applysite.equals("")) {
			map.put("status", 1);
		}else {
			map.put("status", 0);
		}
		return getSqlMapClientTemplate().queryForList("TBDAMAGEDGOODS.selectUnknown", map);
	}

	@Override
	public Integer selectUnknownCount(String entersite, String recedateStart, String recedateEnd,
			String receclass,String memo,String goodsid,String applysite) {
		// TODO Auto-generated method stub
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("entersite", entersite);
		map.put("recedateStart", recedateStart);
		map.put("recedateEnd", recedateEnd);
		map.put("receclass", receclass);
		map.put("memo", memo);
		map.put("goodsid", goodsid);
		map.put("applysite", applysite);
		if(applysite ==null || applysite.equals("")) {
			map.put("status", 1);
		}else {
			map.put("status", 0);
		}
		return (Integer) getSqlMapClientTemplate().queryForObject("TBDAMAGEDGOODS.selectUnknownCount", map);
	}

	@Override
	public List<Tbdamagedimage> selectImage(String seqid) {
		// TODO Auto-generated method stub
		List<Tbdamagedimage> list = new ArrayList<>();
		list = getSqlMapClientTemplate().queryForList("TBDAMAGEDIMAGE.selectImage", seqid);
		return list;
	}

	@Override
	public Tbdamagedgoods selectGoodsByseqid(String seqid) {
		// TODO Auto-generated method stub
		return (Tbdamagedgoods) getSqlMapClientTemplate().queryForObject("TBDAMAGEDGOODS.selectGoodsByseqid",seqid);
	}

	@Override
	public int updateGoodsApplySta(int applysta, String seqid) {
		// TODO Auto-generated method stub
		Map<String,Object> map = new HashMap<>();
		map.put("applysta", applysta);
		map.put("seqid", seqid);
		return getSqlMapClientTemplate().update("TBDAMAGEDGOODS.updateGoodsApplySta", map);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Tbdamagedunknown> selectApply(String seqid) {
		return getSqlMapClientTemplate().queryForList("TBDAMAGEDUNKNOWN.selectApplyBySeqid",seqid);
	}
	
	public Tbdamagedunknown selectApply(int id) {
		return (Tbdamagedunknown) getSqlMapClientTemplate().queryForObject("TBDAMAGEDUNKNOWN.selectApplyById",id);
	}

	@Override
	public int selectRepetCount(String seqid, String applysite) {
		// TODO Auto-generated method stub
		Map<String,Object> map = new HashMap<>();
		map.put("seqid", seqid);
		map.put("applysite", applysite);
		return (int) getSqlMapClientTemplate().queryForObject("TBDAMAGEDUNKNOWN.selectRepetCount",map);
	}

	@Override
	public void insertApply(Tbdamagedunknown tbdu) {
		// TODO Auto-generated method stub
		getSqlMapClientTemplate().insert("TBDAMAGEDUNKNOWN.insertApply", tbdu);
	}

	@Override
	public int updateApplyStatus(int status, int id) {
		// TODO Auto-generated method stub
		Map<String,Object> map = new HashMap<>();
		map.put("status", status);
		map.put("id", id);
		return getSqlMapClientTemplate().update("TBDAMAGEDUNKNOWN.updateApplyStatus", map);
	}

	@Override
	public int updateVerify(Tbdamagedunknown tbdu) {
		// TODO Auto-generated method stub
		return getSqlMapClientTemplate().delete("TBDAMAGEDUNKNOWN.updateVerify", tbdu);
	}

	@Override
	public int delApplyByid(int id) {
		// TODO Auto-generated method stub
		return 0;
	}

	
}
